﻿using KongMing.WebTools.Common;
using Newtonsoft.Json;
using KongMing.WebTools.Contract;

namespace KongMing.WebTools.Models
{
    public class OrmModel
    {
        /// <summary>
        /// 表的c#类名
        /// </summary>
        public string TableName { get; set; }
        /// <summary>
        /// Sql表名
        /// </summary>
        public string SqlTableName { get; set; }
        /// <summary>
        /// 表说明
        /// </summary>
        public string TableRemark { get; set; }
        /// <summary>
        /// sql表字段名的前缀
        /// </summary>
        public string SqlFieldPreFix { get; set; }
        /// <summary>
        /// sql字段是否转小写
        /// </summary>
        public bool SqlFieldLowerCase { get; set; }
        /// <summary>
        /// sql字段是否分割单词  UserName => User_Name  
        /// </summary>
        public bool SqlFieldSplitWords { get; set; }
        /// <summary>
        /// 实体基类名
        /// </summary>
        public string BaseEntityName { get; set; }
        /// <summary>
        /// 基类 带基础字段
        /// </summary>
        public bool WithBaseFields { get; set; }
        /// <summary>
        /// 是否添加ORM字段特性
        /// </summary>
        public bool WithOrmAttribute { get; set; }
        /// <summary>
        /// C#实体是否携带默认值
        /// </summary>
        public bool CsEntityWithDefalueValue { get; set; }
        /// <summary>
        /// Orm类型
        /// </summary>
        public OrmType OrmType { get; set; }
        /// <summary>
        /// 拓展业务场景
        /// </summary>
        public ExpandScanType ScanType { get; set; }
        /// <summary>
        /// 字段集合
        /// </summary>
        public List<Field> Fields { get; set; } = new List<Field>();
        /// <summary>
        /// 克隆一个新实例
        /// </summary>
        public OrmModel Clone()
        {
            var json = JsonConvert.SerializeObject(this);
            return JsonConvert.DeserializeObject<OrmModel>(json)!;
        }
    }
}
